package com.yuwei.controller;

import com.alibaba.fastjson.JSON;
import com.yuwei.bean.Meta;
import com.yuwei.bean.Role;
import com.yuwei.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping("/roles")
    public String getRoles(){
        List<Role> roles = roleService.getRoles();
        Meta retMeta = new Meta();
        retMeta.setStatus(200);
        retMeta.setMsg("获取权限列表成功");
        Object retData = new Object() {
            public List<Role> data = roles;
            public Meta meta = retMeta;
        };
        return JSON.toJSONString(retData);
    }

    @DeleteMapping("/roles/{roleID}/{mgrID}/{typeID}/{rightID}")
    public String delRoleByID(@PathVariable  int roleID,
                              @PathVariable int mgrID,
                              @PathVariable int typeID,
                              @PathVariable int rightID){
        List<Role> roles = roleService.delRoleByID(roleID, mgrID, typeID, rightID);
        Meta retMeta = new Meta();
        retMeta.setMsg("删除权限成功");
        retMeta.setStatus(200);
        Object retData = new Object() {
            public Meta meta = retMeta;
            public List<Role> data = roles;
        };
        return JSON.toJSONString(retData);
    }
}
